package com.network.topo.snmp;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.snmp4j.Target;

import com.network.util.snmp4j.SnmpGet;
import com.network.util.snmp4j.SnmpGetResultSet;

public final class IpNetToMediaTable extends AbstractXxxTable
{
	private static ArrayList<String> oidList = null;
	private HashMap<Object, RowData> objDataMap = new HashMap<Object, RowData>();
	private HashMap<Object, RowData> indexDataMap = new HashMap<Object, RowData>();
	private int rowCount = 0;

	private IpNetToMediaTable(SnmpGetResultSet resultSet)
	{
		this.resultSet = resultSet;
		if (this.resultSet != null)
		{
			rowCount = this.resultSet.getRowCount();
			for (int i = 0; i < rowCount; i++)
			{
				RowData rowData = new RowData();
				int oidIndex = 0;
				rowData.ipNetToMediaIfIndex = str2int(getValue(getOidList().get(oidIndex++), i));
				rowData.ipNetToMediaPhysAddress = getValue(getOidList().get(oidIndex++), i);
				rowData.ipNetToMediaNetAddress = getValue(getOidList().get(oidIndex++), i);
				// rowData.ipNetToMediaType =
				// str2int(getValue(getOidList().get(oidIndex++), i));
				// rowData.ipNetToMediaState =
				// str2int(getValue(getOidList().get(oidIndex++), i));
				indexDataMap.put(i, rowData);
				objDataMap.put(rowData.getIpNetToMediaIfIndex(), rowData);
				objDataMap.put(rowData.getIpNetToMediaPhysAddress(), rowData);
				if (objDataMap.get(rowData.getIpNetToMediaNetAddress()) == null)
				{
					objDataMap.put(rowData.getIpNetToMediaNetAddress(), rowData);
				}
			}
		}
	}

	public static IpNetToMediaTable getInstance(SnmpGet snmpGet, Target target)
	{
		SnmpGetResultSet sgrs = null;
		IpNetToMediaTable instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new IpNetToMediaTable(sgrs);
		}
		return instance;
	}
	public static IpNetToMediaTable getInstance(SnmpGet snmpGet, Target target, List<String> commList)
	{
		SnmpGetResultSet sgrs = null;
		IpNetToMediaTable instance = null;
		try
		{
			sgrs = snmpGet.query(getOidList(), target,commList);
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
		if (sgrs != null && sgrs.next() == true)
		{
			instance = new IpNetToMediaTable(sgrs);
		}
		return instance;
	}

	public static synchronized ArrayList<String> getOidList()
	{
		if (oidList == null)
		{
			oidList = new ArrayList<String>();
			oidList.add("1.3.6.1.2.1.4.22.1.1");
			oidList.add("1.3.6.1.2.1.4.22.1.2");
			oidList.add("1.3.6.1.2.1.4.22.1.3");
			// oidList.add("1.3.6.1.2.1.4.22.1.4");
			// oidList.add("1.3.6.1.2.1.4.22.1.5");
		}
		return oidList;
	}

	public int getIpNetToMediaIfIndex(Object obj, boolean useIndex)
	{
		int rtnValue = 0;
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getIpNetToMediaIfIndex();
		}
		return rtnValue;
	}

	public String getIpNetToMediaPhysAddress(Object obj, boolean useIndex)
	{
		String rtnValue = "0.0.0.0";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getIpNetToMediaPhysAddress();
		}
		return rtnValue;
	}

	public String getIpNetToMediaNetAddress(Object obj, boolean useIndex)
	{
		String rtnValue = "0.0.0.0";
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getIpNetToMediaNetAddress();
		}
		return rtnValue;
	}

	public int getIpNetToMediaType(Object obj, boolean useIndex)
	{
		int rtnValue = 0;
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getIpNetToMediaType();
		}
		return rtnValue;
	}

	public int getIpNetToMediaState(Object obj, boolean useIndex)
	{
		int rtnValue = 0;
		RowData rowData = null;
		if (useIndex)
		{
			rowData = indexDataMap.get(obj);
		}
		else
		{
			rowData = objDataMap.get(obj);
		}
		if (rowData != null)
		{
			rtnValue = rowData.getIpNetToMediaState();
		}
		return rtnValue;
	}
	public class RowData
	{
		private int ipNetToMediaIfIndex = 0;
		private String ipNetToMediaPhysAddress = "";
		private String ipNetToMediaNetAddress = "";
		private int ipNetToMediaType = 0;
		private int ipNetToMediaState = 0;

		public int getIpNetToMediaIfIndex()
		{
			return ipNetToMediaIfIndex;
		}

		public void setIpNetToMediaIfIndex(int ipNetToMediaIfIndex)
		{
			this.ipNetToMediaIfIndex = ipNetToMediaIfIndex;
		}

		public String getIpNetToMediaNetAddress()
		{
			return ipNetToMediaNetAddress;
		}

		public void setIpNetToMediaNetAddress(String ipNetToMediaNetAddress)
		{
			this.ipNetToMediaNetAddress = ipNetToMediaNetAddress;
		}

		public String getIpNetToMediaPhysAddress()
		{
			return ipNetToMediaPhysAddress;
		}

		public void setIpNetToMediaPhysAddress(String ipNetToMediaPhysAddress)
		{
			this.ipNetToMediaPhysAddress = ipNetToMediaPhysAddress;
		}

		public int getIpNetToMediaState()
		{
			return ipNetToMediaState;
		}

		public void setIpNetToMediaState(int ipNetToMediaState)
		{
			this.ipNetToMediaState = ipNetToMediaState;
		}

		public int getIpNetToMediaType()
		{
			return ipNetToMediaType;
		}

		public void setIpNetToMediaType(int ipNetToMediaType)
		{
			this.ipNetToMediaType = ipNetToMediaType;
		}
	}

	public int getRowCount()
	{
		return rowCount;
	}

	public void setRowCount(int rowCount)
	{
		this.rowCount = rowCount;
	}
}
